package br.com.async.agilequiz.activity;

import java.security.NoSuchAlgorithmException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import br.com.async.agilequiz.controller.user.UserController;
import br.com.async.agilequizapp.R;

public class LoginActivity extends Activity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		
		Button btlogin = (Button)findViewById(R.id.btLogin);
		btlogin.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				UserController controller = new UserController();
				
				EditText username = (EditText) findViewById(R.id.etUsername);
				EditText password = (EditText) findViewById(R.id.etPassword);
				
				System.out.println(username.getText().toString());
				System.out.println(password.getText().toString());
				
				try {
					if(controller.doLogin(username.getText().toString(),password.getText().toString())){
						startActivity(new Intent(LoginActivity.this, QuestionActivity.class));
					}else{
						Toast.makeText(LoginActivity.this, "Dados incorretos!",Toast.LENGTH_SHORT).show();
					}
					
				} catch (NoSuchAlgorithmException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
	}

}
